jQuery.extend({
	//错误码路由
	errCodeRoute: function(errcode, errmsg, callback) {
		switch (errcode += "") {
			case "0":
				break;
			case "10401":
				swal({
					"title": "未登录",
					"text": "点击确定返回到登录页",
					"type": "error",
					"confirmButtonText": "确定",
				}, function(isConfirm) {
					top.location.href = "/logout.do";
				});
				break;
			default:
				swal({
					"title": "操作失败",
					"text": errmsg + "(错误码：" + errcode + ")",
					"type": "error",
					"confirmButtonText": "确定",
				}, function(isConfirm) {
					if ($.isFunction(callback)) {
						callback();
					}
				});
		}
	},
	//错误状态路由
	errStatusRoute: function(textstatus, error, callback, jqXHR) {
		var msg = "";
		switch (textstatus) {
			case "abort":
				break;
			case "timeout":
				msg = "接口连接超时";
				break;
			default:
				msg = jqXHR.status;
				break;
		}
		if (msg == "302") {
			//重定向判定为未登录
			$.errCodeRoute("10401");
		} else if (msg) {
			swal({
				"title": "接口访问失败！",
				"type": "error",
				"text": msg,
				"confirmButtonText": "确定",
			}, function(isConfirm) {
				if (callback && $.isFunction(callback)) {
					callback();
				}
			});
		}
	},
	//封装ajax
	wmajax: function(_method, _api, _data, _suc, _other) {
		if (typeof(_method) == "string") {
			if (_api.indexOf("?") >= 0) {
				var search = _api.split("?")[1];
				_api = _api.split("?")[0];
				var sobj = {};
				$.each(search.split("&"), function(index, value) {
					var arr = value.split("=");
					sobj[arr[0]] = arr[1];
				})
				if (_data) {
					_data = $.extend(sobj, _data)
				} else {
					_data = sobj
				};
			}
			if (_data) {
				$.each(_data, function(key, value) {
					if (typeof(value) == "string") {
						_data[key] = $.html2Escape(value);
					}
				});
			}
			var ajaxsettings = {
				type: _method,
				url: _api,
				data: _data,
				suc: _suc,
				timeout: 5000,
				hasAlert: true,
				loadingContainer: $("body")
			};
			if (_other == "json") {
				ajaxsettings.data = JSON.stringify(_data);
				ajaxsettings.contentType = "application/json";
			} else if (_other instanceof jQuery) {
				ajaxsettings.loadingContainer = _other;
			} else if (_other && typeof(_other) == "object") {
				ajaxsettings = $.extend(ajaxsettings, _other);
			}
		} else if (_method && typeof(_method) == "object") {
			if (_method.data) {
				$.each(_method.data, function(key, value) {
					_method.data[key] = $.html2Escape(value);
				});
			}
			var ajaxsettings = $.extend(_method, {
				hasAlert: true,
				loadingContainer: $("body")
			});
		}
		return $.ajax(ajaxsettings);
	},
	//封装post,自动loading,自动alert错误,过滤标签
	wmpost: function(_api, _data, _suc, _other) {
		if ($.isFunction(_data)) {
			_other = _other || _suc;
			_suc = _data;
			_data = undefined;
		}
		return $.wmajax("post", _api, _data, _suc, _other);
	},
	//封装get,自动loading,自动alert错误,过滤标签
	wmget: function(_api, _data, _suc, _other) {
		if ($.isFunction(_data)) {
			_other = _other || _suc;
			_suc = _data;
			_data = undefined;
		}
		return $.wmajax("get", _api, _data, _suc, _other);
	},
	//标签转义
	html2Escape: function(sHtml) {
		return sHtml.replace(/[<>&"]/g, function(c) {
			return {
				'<': '&lt;',
				'>': '&gt;',
				'&': '&amp;',
				'"': '&quot;'
			} [c];
		});
	},
	//标签反转义
	escape2Html: function(str) {
		var arrEntities = {
			'lt': '<',
			'gt': '>',
			'nbsp': ' ',
			'amp': '&',
			'quot': '"'
		};
		return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function(all, t) {
			return arrEntities[t];
		});
	},
	//弹出框
	alert: function(text, type, callback) {
		if (swal && $.isFunction(swal)) {
			swal({
				title: "",
				text: text,
				type: type,
				confirmButtonText: "确定",
			}, function(isConfirm) {
				if (isConfirm && callback && $.isFunction(callback)) {
					callback(isConfirm);
				}
			});
		} else {
			alert(text);
			callback(true);
		}
	},
	//警告框
	confirm: function(text, confirmFunction, cancelFunction, closeOnConfirm) {
		if (!$.isFunction(cancelFunction) && typeof(cancelFunction) == "boolean" && $.isNull(closeOnConfirm)) {
			closeOnConfirm = cancelFunction;
		}
		if (swal && $.isFunction(swal)) {
			swal({
				title: "",
				text: text,
				type: "info",
				showConfirmButton: true,
				showCancelButton: true,
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				closeOnConfirm: closeOnConfirm == false ? false : true,
				showLoaderOnConfirm: closeOnConfirm == false ? true : false
			}, function(isConfirm) {
				if (isConfirm && $.isFunction(confirmFunction)) {
					confirmFunction();
				} else if (!isConfirm && $.isFunction(cancelFunction)) {
					cancelFunction();
				}
			});
		}
	},

	//验证初始化
	verInit: function($container) {
		if (!$container) {
			$container = $("body");
		}
		var sucGlyphicon = '<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>';
		var errGlyphicon = '<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>';

		$container.find(".has-feedback").each(function() {
			$(this).append(sucGlyphicon);
			$(this).append(errGlyphicon);
		});

		$container.on("change", ".required,[required=required],[valueType]", function() {
			$.ver($(this));
		}).on("blur", ".required,[required=required],[valueType]", function() {
			$.ver($(this));
		});
	},
	//验证选择器
	ver: function($input) {
		var n = 0;
		$input.each(function() {
			var $this = $(this);
			var val = $.trim($this.val());
			var minSize = $this.attr("minsize");
			var maxSize = $this.attr("maxsize");
			if ($this.attr("required") && val == "") {
				//非空必填
				err($this, "该项为必填！");
			} else if ((minSize && val.length < parseInt(minSize)) || (maxSize && val.length > parseInt(maxSize))) {
				//长度不符
				var text = "";
				if (minSize && maxSize) {
					text = "长度为" + minSize + "~" + maxSize + "！";
				} else if (minSize) {
					text = "最小长度为" + minSize + "！";
				} else if (maxSize) {
					text = "最大长度为" + maxSize + "！";
				};
				err($this, text);
			} else if ($this.attr("valuetype") && val != "") {
				switch ($this.attr("valuetype")) {
					case "int":
						var reg = /^-?\d+$/;
						var maxvalue = parseInt($this.attr("maxvalue"));
						var minvalue = parseInt($this.attr("minvalue"));
						if (!reg.test(val)) {
							err($this, "该项为整数！");
						} else if (!$.isNull(maxvalue) && !$.isNull(minvalue) && (parseInt(val) > maxvalue || parseInt(val) < minvalue)) {
							err($this, "范围为" + minvalue + "~" + maxvalue + "！");
						} else if (!$.isNull(maxvalue) && parseInt(val) > maxvalue) {
							err($this, "最大值为" + maxvalue + "！");
						} else if (!$.isNull(minvalue) && parseInt(val) < minvalue) {
							err($this, "最小值为" + minvalue + "！");
						} else {
							suc($this);
						}
						break;
					case "number":
						var maxvalue = parseFloat($this.attr("maxvalue"));
						var minvalue = parseFloat($this.attr("minvalue"));
						if (!$.isNumeric(val)) {
							err($this, "该项为数字！");
						} else if (!$.isNull(maxvalue) && !$.isNull(minvalue) && (parseFloat(val) > maxvalue || parseFloat(val) < minvalue)) {
							err($this, "范围为" + minvalue + "~" + maxvalue + "！");
						} else if (!$.isNull(maxvalue) && parseFloat(val) > maxvalue) {
							err($this, "最大值为" + maxvalue + "！");
						} else if (!$.isNull(minvalue) && parseFloat(val) < minvalue) {
							err($this, "最小值为" + minvalue + "！");
						} else {
							suc($this);
						}
						break;
					case "email":
						var reg = /(^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$)/;
						reg.test(val) ? suc($this) : err($this, "请输入正确的Email!");
						break;
					case "idcard":
						var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
						reg.test(val) ? suc($this) : err($this, "请输入正确的身份证号！");
						break;
					case "mobile":
						var reg = /(^[1][3,4,5,7,8][0-9]{9}$)/;
						reg.test(val) ? suc($this) : err($this, "请输入正确的手机号！");
						break;
					case "tel":
						var reg = /(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}/;
						reg.test(val) ? suc($this) : err($this, "请输入正确的电话号码！");
						break;
					case "english":
						var reg = /([a-zA-Z])/;
						reg.test(val) ? suc($this) : err($this, "请输入英文字母！");
						break;
					case "ennum":
						var reg = /([a-zA-Z0-9])/;
						reg.test(val) ? suc($this) : err($this, "请输入英文字母或数字！");
						break;
					case "chinese":
						var reg = /([\u4e00-\u9fa5])/;
						reg.test(val) ? suc($this) : err($this, "请输入汉字！");
						break;
					case "username":
						var reg = /(^\w+$)/;
						reg.test(val) ? suc($this) : err($this, "请输入英文，数字或下划线！");
						break;
						break;
					case "qq":
						var reg = /[1-9][0-9]{4,}/;
						reg.test(val) ? suc($this) : err($this, "请输入正确的QQ号！");
						break;
					case "zipcode":
						var reg = /(^[1-9][0-9]{5}$)/;
						reg.test(val) ? suc($this) : err($this, "请输入正确的邮编！");
						break;
					case "year":
						var reg = /^[0-9]{4}$/;
						reg.test(val) ? suc($this) : err($this, "请输入正确的年份！");
						break;
					case "only":
						var queryData = {};
						queryData[$this.attr("name")] = val;
						if ($this.attr("originalvalue") == val) {
							suc($this);
						} else {
							$.ajax({
								type: "get",
								url: $this.attr("url"),
								data: queryData,
								async: false,
								suc: function(data) {
									suc($this);
								},
								err: function(jqXHR, statusText, data) {
									err($this, data.errmsg || "该数据已存在！");
								}
							});
						}
						break;
				}
			} else {
				suc($this);
			}
		});

		function suc($r) {
			$r.parent().removeClass("has-error").addClass("has-success");
		};

		function err($r, text) {
			n++;
			$r.parent().removeClass("has-success").addClass("has-error").find(".popover").remove();
			var $popover = $("<div>", {
				"class": "popover fade bottom in",
				"role": "tooltip",
				"style": "top: 25px; left: auto; right:32px; transform: translateX(50%); display: block;"
			});
			$popover.append('<div class="arrow" style="left: 50%;"></div><div class="popover-content">' + text + '</div>');
			$r.after($popover);
			$(document).on("mousedown", removePopover);

			function removePopover() {
				$popover.remove();
				$(document).off("mousedown", removePopover);
			};
		};
		if (n > 0) {
			return false;
		} else {
			return true;
		}
	},
	//判断是否IE
	isIE: function() {
		if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
			return true;
		} else {
			return false;
		}
	},
	//判断是否IE几+
	isWhichIEAndPlus: function(version) {
		var userAgent = navigator.userAgent.toLowerCase();
		var bool = false;
		if (!/msie/.test(userAgent)) {
			bool = true;
		} else {
			for (n = version; n <= 11; n++) {
				if (userAgent.indexOf("msie " + n) > 0) {
					bool = true;
					break;
				}
			}
		}
		return bool;
	},
	// 判断是否为空
	isNull: function(data) {
		return !data ? (data === 0 ? false : true) : false;
	},
	//保留小数点后num位
	toFixed: function(float, num) {
		if (num == null) {
			num = 2;
		}
		if ($.isNumeric(float)) {
			return (float + "").indexOf(".") > 0 ? parseFloat(float).toFixed(num) : float;
		} else {
			return 0;
		}
	},
	//num转货币格式(强制保留小数点后两位)
	numToMoney: function(s) {
		s += "";
		var bool = false;
		if (s.substr(0, 1) == "-") {
			bool = true;
			s = s.replace("-", "");
		}
		if (/[^0-9\.]/.test(s)) return "0";
		s = s.replace(/^(\d*)$/, "$1.");
		s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
		s = s.replace(".", ",");
		var re = /(\d)(\d{3},)/;
		while (re.test(s))
			s = s.replace(re, "$1,$2");
		s = s.replace(/,(\d\d)$/, ".$1");
		return bool ? "-" + s.replace(/^\./, "0.") : s.replace(/^\./, "0.");
	},
	//设置cookies
	setCookie: function(name, value) {
		var Days = 30;
		var exp = new Date();
		exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
		document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
	},
	//读取cookies 
	getCookie: function(name) {
		var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
		if (arr = document.cookie.match(reg)) {
			return unescape(arr[2]);
		} else {
			return null;
		}
	},
	//删除cookies 
	delCookie: function(name) {
		var exp = new Date();
		exp.setTime(exp.getTime() - 1);
		var cval = getCookie(name);
		if (cval != null)
			document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
	},
	//字符串替换(字符串,要替换的字符,替换成什么)
	//replaceAll('abcaac','a',0)
	replaceAll: function(str, AFindText, ARepText) {
		raRegExp = new RegExp(AFindText, "g");
		return str.replace(raRegExp, ARepText);
	},
	//json转string
	jsonToStr: function(json) {
		return JSON.stringify(json);
	},
	//string转json
	strToJson: function(str) {
		var json = eval('(' + str + ')');
		return json;
	},
	//获得页面参数
	getPara: function(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return this.html2Escape(decodeURIComponent(r[2]));
		return null;
	},
	//格式字符串长度
	formatLength: function(value, maxlength, defaltWord) {
		if (!$.isNull(value)) {
			if (maxlength > 0) {
				if (value.length > parseInt(maxlength)) {
					value = value.substr(0, parseInt(maxlength)) + "...";
				}
			}
		} else {
			value = defaltWord || "";
		}
		return value;
	},
	//时间戳转时间
	unixToDate: function(unixTime, type) {
		var time = new Date(unixTime);
		type = type || 1;
		if (typeof(type) == "number") {
			switch (type) {
				case 1:
					return time.format("yyyy-MM-dd hh:mm:ss");
					break;
				case 2:
					return time.format("yyyy-MM-dd");
					break;
				case 3:
					return time.format("hh:mm:ss");
					break;
			}
		} else if (typeof(type) == "string") {
			return time.format(type);
		}
	},
	//时间字符串转时间
	dateToUnix: function(stringTime) {
		var unix = Number(new Date(stringTime.replace(new RegExp(/-/gm), "/")));
		//unix = unix / 1000;
		return unix;
	},
	open: function(type, url, para) {
		var $form = $("<form>", {
			target: "_blank",
			method: type,
			action: url,
			style: "display:none"
		}).appendTo($("body"));
		if (para) {
			$.each(para, function(k, v) {
				$form.append($("<textarea>", {
					name: k,
					value: v
				}).html(v))
			})
		}
		$form[0].submit();
		$form.remove();
	},
	getOpen: function(url, para) {
		this.open("get", url, para);
	},
	postOpen: function(url, para) {
		this.open("post", url, para);
	},
	//生成随机gid
	getuid: function() {
		var arr = [];
		for (n = 0; n < 4; n++) {
			arr.push((((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1))
		};
		return arr.join("-");
	},
	//生成随机颜色
	getRandomColor: function() {
		var c = '#';
		var cArray = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
		for (var i = 0; i < 6; i++) {
			var cIndex = Math.round(Math.random() * 15);
			c += cArray[cIndex];
		}
		return c;
	},
	//获得当前时间
	getNowTime: function(type) {
		return this.unixToDate(new Date().valueOf(), type);
	},
});
jQuery.fn.extend({
	loading: function(options) {
		var loadingContainer = $(this).addClass("pos-rel");
		options = $.extend({
			"loadingType": "img",
			"loadingImg": "",
			"loadingText": "正在加载...",
			"position": loadingContainer.is("body") ? "fixed" : "absolute"
		}, options);
		if (options.loadingType == "img") {
			var loading = $('<div>', {
				"class": "loading now-loading loading-img",
				style: "position:" + options.position + ";"
			});
			loading.append($('<div>', {
				"class": "loading-gif"
			})).appendTo(loadingContainer);
		} else if (options.loadingType == "text") {
			var loading = $('<div>', {
				"class": "loading now-loading loading-text text-center"
			});
			loading.text(options.loadingText).appendTo(loadingContainer);
		} else if (options.loadingType == "css3") {
			var loading = $('<div>', {
				"class": "loading now-loading loading-img text-center",
				style: "position:" + options.position + ";"
			});
			loading.append($('<div>', {
				"class": "loader"
			}).append('<div class="face"><div class="circle"></div></div><div class="face"><div class="circle"></div></div>')).appendTo(loadingContainer);
		}
		return loadingContainer;
	},
	endLoading: function() {
		var loadingContainer = $(this);
		loadingContainer.each(function() {
			var $this = $(this);
			if ($this.find(">.now-loading:eq(0)").length > 0) {
				$this.find(">.now-loading:eq(0)").removeClass("now-loading").fadeOut(function() {
					$(this).remove();
					if ($this.find(">.now-loading").length == 0) {
						$this.removeClass("pos-rel");
					}
				});
			}
		});
		return loadingContainer;
	},
	//在select中生成option
	createOption: function(options) {
		options = $.extend({
			list: [],
			valueKey: "id",
			nameKey: "name",
			defaultOption: ""
		}, options);
		var $this = $(this);
		var html = options.defaultOption ? '<option value="">&lt;' + options.defaultOption + '&gt;</option>' : '';
		$.each(options.list, function(index, obj) {
			html += '<option value="' + obj[options.valueKey] + '">' + obj[options.nameKey] + '</option>';
		});
		$this.html(html);
		return $this;
	},
	/*重置容器内表单*/
	resetForm: function() {
		var $this = $(this);
		$this.find(".has-feedback").removeClass("has-success").removeClass("has-error");
		$this.find(".form-control").val("");
		$this.find(".file-list li").remove();
		return $this;
	},
	/*发送指定容器内表单*/
	sendForm: function(options) {
		options = $.extend({
			url: "",
			method: "post",
			data: {},
			beforeSend: function(data) {
				return data;
			},
			callback: function(data) {

			},
			loadingContainer: null
		}, options);
		var $this = $(this);
		if (!$.ver($this.find(".form-control[required=required]"))) {
			return false;
		}
		var formdata = {};
		$this.find(".form-control:not(.prevent)").each(function(index) {
			if (options.method === "post" && options.contentType === "application/json") {
				if (index == 0) {
					formdata.propertyValueCustomList = [];
				}
				formdata.propertyValueCustomList.push({
					englishName: $(this).attr("name"),
					sxid: $(this).attr("data-sxid"),
					sxValue: $(this).val(),
					lbId: $(this).attr("data-lbid")
				});
			} else if ($(this).attr("formtype") == "money" && $(this).val()) {
				formdata[$(this).attr("name")] = parseInt(parseFloat($(this).val()) * 100) + "";
			} else {
				formdata[$(this).attr("name")] = $(this).val();
			}
		});
		$this.find("input[type=radio]").each(function() {
			formdata[$(this).attr("name")] = $this.find("input[type=radio][name=" + $(this).attr("name") + "]:checked").val();
		});

		//处理上传文件
		$this.find(".file-upload-container").each(function() {
			var field = $(this).attr("data-field");
			var $fileList = $(this).find(".file-list");
			var fileList = [];
			$fileList.find("li.upload-file").each(function() {
				fileList.push($(this).attr("data-id"));
			});
			if (options.method === "post" && options.contentType === "application/json") {
				formdata.propertyValueCustomList.push({
					englishName: $(this).attr("data-field"),
					sxid: $(this).attr("data-sxid"),
					sxValue: fileList.toString(),
					lbId: $(this).attr("data-lbid")
				});
			} else {
				formdata[field] = fileList.toString();
			}
		});
		formdata = $.extend(formdata, options.data);
		formdata = options.beforeSend(formdata);
		var ajaxSetting = {
			url: options.url,
			type: options.method,
			data: formdata,
			suc: function(data) {
				$.alert(data.errmsg, "success", function() {
					$this.modal("hide");
					if (options.callback && $.isFunction(options.callback)) {
						options.callback(data);
					}
				});
			},
			hasAlert: true,
			loadingContainer: options.loadingContainer || $this
		};
		if (options.method === "post" && options.contentType === "application/json") {
			ajaxSetting.data = JSON.stringify(formdata);
			ajaxSetting.contentType = "application/json";
		}
		if (options.url) {
			$.ajax(ajaxSetting);
		}
		return formdata;
	},
	//建表格
	createTable: function(options) {
		var $this = $(this);
		options = $.extend({
			"method": "post",
			"pageNo": 1,
			"pageSize": 10,
			"url": "",
			"data": [],
			"undefinedText": '-',
			"showCheckbox": true,
			"pagination": true,
			"dataField": "rows",
			"totalField": 'totalCount',
			"simpleSort": true,
			"columns": [{
				checkbox: true,
			}],
			"searchFormList": $(".search-form .form-control"),
			"onClickCell": function(field, value, row) {

			},
			"onPostBody": function() {

			},
			"onLoadSuccess": function(data) {

			},
			"addData": {},
			"showColumns": true,
			"showRefresh": true,
			"extendData": {}
		}, options);
		if (!options.simpleSort) {
			var ordering = {};
			var $orderlist = $("<div>", {
				"class": "columns columns-left orderlist pull-left"
			});
			var times = 0;
		};

		function getTitleByField(field) {
			var title;
			$.each(options.columns, function(index, obj) {
				if (field == obj["field"]) {
					title = obj["title"];
					return false;
				}
			});
			return title;
		};

		function addToOrderList(params) {
			var $order = $("<span>", {
				"class": "label label-primary pt5 pr5 pb5 pl5 mr5",
				"data-field": params.sort,
				"data-order": params.order
			});
			$order.html(getTitleByField(params.sort) + " <span class='order pointer " + params.order + "'>" + (params.order == "desc" ? "降序 " : "升序 ") + "</span> ");
			$order.append($("<span>", {
				"class": "glyphicon glyphicon-remove remove pointer"
			}));
			$orderlist.prepend($order);
			$order.on("click", ".remove", function() {
				if (ordering[params.sort]) {
					delete ordering[params.sort];
				};
				var index = $order.index($orderlist.find(".label"));
				$order.remove();
				if ($orderlist.find("span.label").length > 0) {
					if (index == 0) {
						var $first = $orderlist.find("span.label:eq(0)");
						$this.bootstrapTable("refreshOptions", {
							sortName: $first.attr("data-field"),
							sortOrder: $first.attr("data-order")
						});
					} else {
						$this.bootstrapTable("refresh");
					}
				} else {
					$this.bootstrapTable("refreshOptions", {
						sortName: "",
						sortOrder: ""
					});
				}
				times = 0;
			}).on("click", ".order", function() {
				if (ordering[params.sort]) {
					if ($order.index($orderlist.find("span.label")) == 0) {
						$this.find("thead th[data-field=" + params.sort + "] div.sortable").trigger("click");
					} else {
						if ($(this).hasClass("desc")) {
							$(this).removeClass("desc").addClass("asc").html("升序");
							ordering[params.sort] = "asc";
						} else {
							$(this).removeClass("asc").addClass("desc").html("降序");
							ordering[params.sort] = "desc";
						}
						$this.bootstrapTable("refresh");
					}
				};
			});
		}
		var bootstrapTableSetting = {
			url: options.url,
			data: options.data,
			contentType: options.contentType,
			method: options.method,
			dataField: options.dataField,
			sidePagination: "server", //client or server
			striped: true,
			pagination: options.pagination,
			paginationLoop: false,
			search: false,
			showRefresh: options.showRefresh,
			showColumns: options.showColumns,
			silent: true,
			pageNumber: 1,
			pageSize: options.pageSize,
			pageList: options.pageList,
			clickToSelect: false,
			undefinedText: options.undefinedText,
			cache: false,
			columns: options.columns,
			onClickCell: options.onClickCell,
			onPageChange: function(number, size) {

			},
			queryParamsType: "limit",
			queryParams: function(params) {
				var temp = {
					pageNo: params.pageNo,
					pageSize: params.pageSize
				};
				if (options.searchFormList) {
					options.searchFormList.each(function() {
						$(this).val() ? temp[$(this).attr("name")] = $(this).val() : function() {};
					});
				}
				if (params.sort && params.order) {
					if (!options.simpleSort) {
						if (ordering[params.sort]) {
							delete ordering[params.sort];
							$orderlist.find("span[data-field=" + params.sort + "]").remove();
						};
						ordering[params.sort] = params.order;
						addToOrderList(params);
						var orderBy = [];
						$.each(ordering, function(key, value) {
							orderBy.unshift(key + " " + value);
						});
						temp["orderBy"] = orderBy.toString();
					} else {
						temp["orderBy"] = params.sort + " " + params.order
					}
				}
				temp = $.extend(temp, options.addData, options.extendData)
				return options.contentType === "application/json" && options.method === "post" ? JSON.stringify(temp) : temp;
			},
			onPostBody: options.onPostBody,
			onLoadSuccess: function(data) {
				if (!options.simpleSort && !times++) {
					$orderlist.prependTo($this.parents(".bootstrap-table").find(".fixed-table-toolbar"));
					$orderlist.empty();
					$.each(ordering, function(key, value) {
						addToOrderList({
							sort: key,
							order: value
						})
					})
				}
				options.onLoadSuccess(data);
			}
		}
		$(this).bootstrapTable(bootstrapTableSetting);
	},
	//合并行
	mergeCells: function(data, fieldName, colspan) {
		var $this = $(this);
		if (data.length == 0) {
			alert("不能传入空数据");
			return;
		}
		var numArr = [];
		var value = data[0][fieldName];
		var num = 0;
		for (var i = 0; i < data.length; i++) {
			if (value != data[i][fieldName]) {
				numArr.push(num);
				value = data[i][fieldName];
				num = 1;
				continue;
			}
			num++;
		}
		var merIndex = 0;
		for (var i = 0; i < numArr.length; i++) {
			$this.bootstrapTable('mergeCells', {
				index: merIndex,
				field: fieldName,
				colspan: colspan,
				rowspan: numArr[i]
			})
			merIndex += numArr[i];
		}
	},
	//合并列
	mergeColspan: function(data, fieldNameArr) {
		var $this = $(this)
		if (data.length == 0) {
			alert("不能传入空数据");
			return;
		}
		if (fieldNameArr.length == 0) {
			alert("请传入属性值");
			return;
		}
		var num = -1;
		var index = 0;
		for (var i = 0; i < data.length; i++) {
			num++;
			for (var v in fieldNameArr) {
				index = 1;
				if (data[i][fieldNameArr[v]] != data[i][fieldNameArr[0]]) {
					index = 0;
					break;
				}
			}
			if (index == 0) {
				continue;
			}
			$(this).bootstrapTable('mergeCells', {
				index: num,
				field: fieldNameArr[0],
				colspan: fieldNameArr.length,
				rowspan: 1
			});
		}
	},
	//ztreePicker
	ztreePicker: function(options) {
		options = $.extend({
			"list": [],
			"beforeOpen": function($inputText) {
				return [];
			},
			"onCheck": function(personCheckedArr, $simpleInput) {
				var value = []
				if ($.isArray(personCheckedArr) && personCheckedArr.length > 0) {
					$.each(personCheckedArr, function(index, obj) {
						value.push(obj.name)
					})
				}
				$simpleInput.val(value.join(","))
			},
			"onClick": function(e, treeId, treeNode) {

			},
			"condition": function(obj) {
				return true
			},
			"enable": true,
			"idKey": "id",
			"textKey": "name",
			"pIdKey": "pId"

		}, options);

		var $input = $(this);
		//$input.prop("readonly",true)
		$input.each(function(index) {
			var t, nodes, checkedArrList = [],
				$simpleInput = $(this);
			$(this).after('<div class="person-picker dropdown-menu" style="display:none;"><div id="person_ztree_' + parseInt(Math.random() * 1000) + '" class="ztree">loading...</div></div>');
			var $picker = $simpleInput.siblings(".person-picker");
			var $tree = $picker.find(".ztree");

			$simpleInput.off("focus").on("focus", function() {
				showPicker();
				var closeEvent = function() {
					if (!$(event.target).parents(".person-picker").length > 0 && !$(event.target).hasClass("person-picker")) {
						closePicker();
						$(document).off("mousedown", closeEvent);
					}
				}
				$(document).on("mousedown", closeEvent);
			})
			$simpleInput.on("change", function() {
				$(this).attr("data-ztree", "0");
			})

			function closePicker() {
				$picker.hide();
			}

			function showPicker() {
				$picker.show();
				if ($simpleInput.attr("data-ztree") != "1") {
					//checkedArrList = options.beforeOpen($simpleInput)
					checkedArrList = $simpleInput.val() ? $simpleInput.val().split(",") : []
					getAllNodes(checkedArrList);
				}

			}
			ztreeInit($tree, $simpleInput);

			function ztreeInit($tree, $simpleInput) {

				var setting = {
					view: {
						dblClickExpand: true,
						showLine: true,
						selectedMulti: false,
						showIcon: false,
						txtSelectedEnable: true,
						fontCss: function(treeId, treeNode) {
							return options.condition(treeNode) ? {
								'font-weight': 'normal'
							} : {
								'font-weight': 'bold'
							};
						}
					},
					data: {
						key: {
							name: options.textKey || "text"
						},
						simpleData: {
							enable: true,
							idKey: options.idKey,
							pIdKey: options.pIdKey
						}
					},
					check: {
						enable: options.enable
					},
					callback: {
						onCheck: function(e, treeId, treeNode) {
							checkedArr = t.getCheckedNodes(true);
							personCheckedArr = []
							$.each(checkedArr, function(index, obj) {
								options.condition(obj) ? personCheckedArr.push(obj) : function() {}
							});
							options.onCheck(personCheckedArr, $simpleInput);
							$simpleInput.attr("data-ztree", "1")
						},
						onClick: function(e, treeId, treeNode) {
							if (options.condition(treeNode)) {
								options.onClick(e, treeId, treeNode)
								closePicker()
							}
						}

					}
				};

				var zNodes = options.list;
				t = $tree;
				t = $.fn.zTree.init(t, setting, zNodes);
			}

			function getAllNodes(arrayList) {
				t.checkAllNodes(false);
				if ($.isArray(arrayList) && arrayList.length > 0) {
					var a;
					$.each(arrayList, function(index, value) {
						a = t.getNodeByParam(options.textKey, value);
						if (a != null) {
							a.checked = true;
							t.selectNode(a, true)
							t.expandNode(a, true, false);
							t.updateNode(a);
						}
					})
				}
			}

		})
	},
	//生成banner
	creatBanner: function() {
		var bannerContainter = $(this);
		var my_banner_01 = 0;
		var my_banner_01_count = 0;
		var my_banner_01_num = 0;

		my_banner_01_count = bannerContainter.find("a").length;
		var bannerHtml = bannerContainter.html();
		bannerContainter.empty();
		var ul = $("<ul></ul>");
		ul.appendTo(bannerContainter);
		var list = $('<div class="my-banner-list"></div>');
		list.appendTo(bannerContainter);
		for (n = 1; n <= my_banner_01_count; n++) {
			if (n == 1) {
				ul.append("<li class='on'>" + n + "</li>")
			} else {
				ul.append("<li>" + n + "</li>")
			}
		}

		list.html(bannerHtml);
		list.find("a:first-child").addClass("on");
		list.find("a:not(:first-child)").hide();
		ul.find("li").click(function() {
			var i = $(this).text() - 1; //获取Li元素内的值，即1，2，3，4
			my_banner_01_num = i;
			if (i >= my_banner_01_count) return;
			list.find("a.on").removeClass("on").fadeOut(500).parent().children().eq(i).addClass("on").fadeIn(1000);
			bannerContainter.css('background', '');
			$(this).toggleClass("on");
			$(this).siblings().removeClass("on");
		});

		var showAutoBanner = function() {
			my_banner_01_num = my_banner_01_num >= (my_banner_01_count - 1) ? 0 : ++my_banner_01_num;
			bannerContainter.find("li").eq(my_banner_01_num).trigger('click');
		}

		my_banner_01 = setInterval(function() {
			showAutoBanner()
		}, 3000);

		bannerContainter.hover(function() {
			clearInterval(my_banner_01)
		}, function() {
			my_banner_01 = setInterval(function() {
				showAutoBanner()
			}, 3000);
		});
	}
})

Date.prototype.format = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份 
		"d+": this.getDate(), //日 
		"h+": this.getHours(), //小时 
		"m+": this.getMinutes(), //分 
		"s+": this.getSeconds(), //秒 
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}
